<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <!-- Viewport-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" />
    <!-- SEO Meta Tags-->
    <meta name="keywords" content="quicky, chat, messenger, conversation, social, communication" />
    <meta name="description" content="Quicky is a Bootstrap based modern and fully responsive Messaging template to help build Messaging or Chat application fast and easy." />
    <meta name="subject" content="communication">
    <meta name="copyright" content="frontendmatters">
    <meta name="revised" content="Sunday, July 18th, 2010, 5:15 pm" />
    <title>{:$configs['SYSTEM_NAME']}</title>
    <!-- Favicon and Touch Icons-->
    <link rel="apple-touch-icon" sizes="180x180" href="./../apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="./../favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="./../favicon-16x16.png">
    <link rel="shortcut icon" href="./../favicon.ico" />
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">
    <link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/materialdesignicons.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/bootstrap.min.css">
    <link rel="stylesheet" href="__STATIC__/index/webfonts/inter/inter.css"> 
    <link rel="stylesheet" href="__STATIC__/index/css/app.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/common/cch.css">


    <style type="text/css">
        #chatContactsList {background: url('__STATIC__/index/theme.ff3f4d0f.png');background-position: center;background-size: 60% auto;background-repeat: no-repeat;}
        #initChats {background: url('__STATIC__/index/empty.787e1a1d.png');background-position: center;background-size: 60% auto;background-repeat: no-repeat;}
        #messageBody {background: url('__STATIC__/index/empty.787e1a1d.png');background-position: center;background-size: 60% auto;background-repeat: no-repeat;}

        /*自动换行*/
        .message-content {white-space: pre-line;}

        .table-bordered th {padding: 10px;}
        .table-bordered td {padding:0 10px 0 10px;}
    </style>
</head>

<body class="chats-tab-open">

    <!-- Main Layout Start -->
    <div class="main-layout">
        <!-- Navigation Start -->
        {include file="agent/menu" /}
        <!-- Navigation End -->
        {include file="agent/session" /}


        <!-- Main Start -->
        <main class="main" style="z-index:1021;">

            <!-- Chats Page Start -->
            <div class="chats" id="msgChats" style="display:none;">
                <!-- Chat Body Start -->
                <div class="chat-body">

                    <!-- Chat Header Start-->
                    <div class="chat-header">
                        <!-- Chat Back Button (Visible only in Small Devices) -->
                        <button class="btn btn-secondary btn-icon btn-minimal btn-sm d-xl-none close_btn_mobile" type="button" data-close="" style="margin-right: 10px;">
                            <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
                            </svg>
                            <!-- <img class="injectable hw-20" src="./../assets/media/heroicons/outline/arrow-left.svg" alt=""> -->
                        </button>

                        <!-- Chat participant's Name -->
                        <div class="media chat-name align-items-center text-truncate">
                            <div class="avatar text-light d-sm-inline-block mr-3">
                                <span>
                                    <img class="injectable" src="__UPLOAD__/{:$data['image']}" alt="">
                                </span>
                            </div>

                            <div class="media-body align-self-center ">
                                <h6 class="text-truncate mb-0">{:$data['name']}</h6>
                                <small class="text-muted" style="display:block;max-width: 180px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;">{:$data['description']}</small>
                            </div>
                        </div>

                        <!-- Chat Options -->
                        <ul class="nav flex-nowrap">
                            <!-- <li class="nav-item list-inline-item d-none d-sm-block mr-1">
                                <a class="nav-link text-muted px-1" data-toggle="collapse" data-target="#searchCollapse" href="#" aria-expanded="false">
                                    <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                                    </svg>
                                </a>
                            </li> -->

                            <!-- <li class="nav-item list-inline-item d-none d-sm-block mr-1">
                                <a class="nav-link text-muted px-1" href="#" title="Add People">
                                    <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/>
                                    </svg>
                                </a>
                            </li> -->
                            <li class="nav-item list-inline-item d-none d-sm-block mr-0">
                                <div class="dropdown">
                                    <a class="nav-link text-muted px-1" href="#" role="button" title="Details" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"/>
                                        </svg>
                                        <!-- <img src="./../assets/media/heroicons/outline/dots-vertical.svg" alt="" class="injectable hw-20"> -->
                                    </a>

                                    <div class="dropdown-menu dropdown-menu-right">
                                        <!-- <a class="dropdown-item align-items-center d-flex" href="#" data-chat-info-toggle="">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                            </svg>
                                              
                                            <span>View Info</span>
                                        </a>

                                        <a class="dropdown-item align-items-center d-flex" href="#">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z" clip-rule="evenodd"/>
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"/>
                                              </svg>
                                            <span>Mute Notifications</span> 
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex" href="#">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                              </svg>
                                            <span>Wallpaper</span>
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex" href="#">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/>
                                              </svg>
                                              
                                            <span>Archive</span>
                                        </a> -->
                                        <a class="dropdown-item align-items-center d-flex" href="javascript:void(0)" onclick="closeSession()">
                                        
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"/>
                                                </svg>
                                              
                                            <span>退出</span>
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex" href="javascript:void(0)" onclick="deleteSession()">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                              </svg>
                                              
                                            <span>删除</span>
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex text-danger" href="javascript:void(0)" onclick="clearSession()">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
                                              </svg>
                                            <span>清空</span>
                                        </a>
                                    </div>
                                </div>
                            </li>
                            <li class="nav-item list-inline-item d-sm-none mr-0">
                                <div class="dropdown">
                                    <a class="nav-link text-muted px-1" href="#" role="button" title="Details" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"/>
                                        </svg>
                                        <!-- <img src="./../assets/media/heroicons/outline/dots-vertical.svg" alt="" class="injectable hw-20"> -->
                                    </a>

                                    <div class="dropdown-menu dropdown-menu-right">
                                        <a class="dropdown-item align-items-center d-flex" href="javascript:void(0)" onclick="$('.close_btn_mobile').trigger('click')">
                                        
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"/>
                                                </svg>
                                              
                                            <span>退出</span>
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex" href="javascript:void(0)" onclick="deleteSessionMobile()">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                              </svg>
                                              
                                            <span>删除</span>
                                        </a>
                                        <a class="dropdown-item align-items-center d-flex text-danger" href="javascript:void(0)" onclick="clearSession()">
                                            <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
                                              </svg>
                                            <span>清空</span>
                                        </a>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <!-- Chat Header End-->

                    <!-- Search Start -->
                    <div class="collapse border-bottom px-3" id="searchCollapse">
                        <div class="container-xl py-2 px-0 px-md-3">
                            <div class="input-group bg-light ">
                                <input type="text" class="form-control form-control-md border-right-0 bg-transparent pr-0" placeholder="Search...">
                                <div class="input-group-append">
                                    <span class="input-group-text bg-transparent border-left-0">
                                        <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                                          </svg>
                                          
                                        <!-- <img class="injectable hw-20" src="./../assets/media/heroicons/outline/search.svg" alt="Search icon"> -->
                                    </span>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                    <!-- Search End -->

                    <!-- Chat Content Start-->
                    <div class="chat-content p-2" id="messageBody">
                        <div class="container" id="chatContent">

                            <!-- Message Day Start -->
                            <div class="message-day">

                                <div class="message-divider sticky-top pb-2" data-label="Yesterday">&nbsp;</div>

                                <!-- Received Message Start -->
                                <div class="message self">
                                    <div class="message-wrapper">
                                        <div class="message-content">
                                            <span>Wow!  Today is October 30th! Halloween is tomorrow already!  Have you decided what you will be dressing up for Halloween yet, Sara?</span>
                                        </div>
                                    </div>
                                    <div class="message-options">
                                        <div class="avatar avatar-sm"><img alt="" src="./../assets/media/avatar/1.png"></div>
                                        <span class="message-date">9:12am</span>
                                        <div class="dropdown">
                                            <a class="text-muted" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-18" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>
                                                </svg>
                                            </a>
        
                                            <div class="dropdown-menu">
                                                <a class="dropdown-item d-flex align-items-center" href="#">
                                                    <svg class="hw-18 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
                                                    </svg>
                                                    <span>Copy</span>
                                                </a>
                                                <a class="dropdown-item d-flex align-items-center text-danger" href="#">
                                                    <svg class="hw-18 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                                    </svg>
                                                    <span>Delete</span>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Received Message End -->

                            </div>
                            <!-- Message Day End -->

                       

                        </div>

                        <!-- Scroll to finish -->
                        <div class="chat-finished" id="chat-finished"></div>
                    </div>
                    <!-- Chat Content End-->


                    <!-- Chat Footer Start-->
                    <div class="chat-footer" style="display:none;">
                        <form>
                            <div class="form-row">
                                <!-- Chat Input Group Start -->
                                <div class="col">
                                    <div class="input-group">
                                        <!-- Attachment Start -->
                                        <div class="input-group-prepend mr-sm-2 mr-1">
                                            <div class="dropdown">
                                                <button class="btn btn-secondary btn-icon btn-minimal btn-sm" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v3m0 0v3m0-3h3m-3 0H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                                    </svg>
                                                      
                                                    <!-- <img class="injectable hw-20" src="./../assets/media/heroicons/outline/plus-circle.svg" alt=""> -->
                                                </button>
                                                <div class="dropdown-menu">
                                                    <a class="dropdown-item" href="#" data-toggle="modal" data-target="#createGroup">
                                                        <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
                                                        </svg>
                                                          
                                                        <!-- <img class="injectable hw-20 mr-2" src="./../assets/media/heroicons/outline/document.svg" alt=""> -->
                                                        <span>合同审查</span>
                                                    </a>
                                                    <a class="dropdown-item" href="#" data-toggle="modal" data-target="#aiDraw">
                                                        <svg class="hw-20 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
                                                        </svg>
                                                          
                                                        <!-- <img class="injectable hw-20 mr-2" src="./../assets/media/heroicons/outline/document.svg" alt=""> -->
                                                        <span>AI作画</span>
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- Attachment End -->
                                
                                        <!-- Emoji Start -->
                                        <div class="input-group-prepend mr-sm-2 mr-1">
                                            <button class="btn btn-secondary btn-icon btn-minimal btn-sm" id="singleOptimizeBtn" type="button" onclick="singleOptimize()" title="优化指令内容">
                                                优
                                            </button>

                                            <button class="btn btn-secondary btn-icon btn-minimal btn-sm" id="loadingOptimizeBtn" type="button" title="指令优化中" style="display: none;">
                                                <div class="spinner-border lyear-loading text-info" style="width: 20px; height: 20px; "></div>
                                            </button>
                                        </div>
                                        <!-- Emoji End -->

                                        <!-- Textarea Start-->
                                        <textarea class="form-control bg-transparent border-0 no-resize hide-scrollbar" id="msg_text" placeholder="请输入你的内容" rows="1"></textarea>
                                        <!-- Textarea End -->
                                    </div>
                                </div>
                                <!-- Chat Input Group End -->
                        
                                <!-- Submit Button Start -->
                                <div class="col-auto">
                                    <div class="btn btn-primary btn-icon rounded-circle text-light mb-1" role="button" onclick="sendMsg()">
                                        <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3"/>
                                        </svg>
                                          
                                        <!-- <img src="./../assets/media/heroicons/outline/arrow-right.svg" alt="" class="injectable"> -->
                                    </div>
                                </div>
                                <!-- Submit Button End-->
                            </div>
                        </form>
                    </div>
                    <!-- Chat Footer End-->
                </div>
                <!-- Chat Body End -->

            </div>
            <!-- Chats Page End -->


            <!-- Chats Page Start -->
            <div class="chats" id="initChats" style="max-width: 100%;position: relative;">
                <div style="width:100%;position: absolute;">
                    <ul class="contacts-list"  data-chat-list="">
                        <?php foreach ($assistants as $k => $vo): ?>
                        <li class="contacts-item init_assistant {:$k==0?'active':''}" data-id="{:$vo['id']}" style="width: 31%;margin:10px 1%;float: left;display: block;">
                            <a class="contacts-link" href="javascript:void(0)">
                                <div class="avatar avatar-online">
                                    <img src="__UPLOAD__/{:$vo['image']}" alt="">
                                </div>
                                <div class="contacts-content">
                                    <div class="contacts-info">
                                        <h6 class="chat-name text-truncate">{:$vo['name']}</h6>
                                    </div>
                                    <div class="contacts-texts">
                                        <p class="text-truncate">{:$vo['description']}</p>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <?php endforeach ?>

                    </ul>
                </div>
                <div style="clear: both;"></div>

                <div class="d-flex flex-column justify-content-center text-center h-100 w-100" >

                    <div class="container">


                        <div class="avatar avatar-lg mb-2">
                            <img class="avatar-img" src="__UPLOAD__/{:$configs['SYSTEM_ICON']}" alt="">
                        </div>

                        <h5>你好，我是{:$configs['SYSTEM_NAME']}！</h5>
                        <p class="text-muted">{:myTextareaShow($configs['SYSTEM_TXT'])}</p>

                        <!-- <button class="btn btn-outline-primary no-box-shadow" type="button" data-toggle="modal" data-target="#startConversation">
                            创建新的对话
                        </button> -->
                        <button class="btn btn-outline-primary no-box-shadow" type="button" onclick="initeCreateSession()">
                            创建新的对话
                        </button>
                    </div>
                </div>
            </div>
            <!-- Chats Page End -->



            <!-- Profile Settings Start -->
            <div class="profile">
                <div class="page-main-heading sticky-top py-2 px-3 mb-3">

                    <!-- Chat Back Button (Visible only in Small Devices) -->
                    <button class="btn btn-secondary btn-icon btn-minimal btn-sm text-muted d-xl-none" type="button" data-close="">
                        <svg class="hw-20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
                          </svg>
                        <!-- <img class="injectable hw-20" src="__STATIC__/index/media/heroicons/outline/arrow-left.svg" alt=""> -->
                    </button>

                    <div class="pl-2 pl-xl-0">
                        <h5 class="font-weight-semibold">设置</h5>
                        <p class="text-muted mb-0">更新个人信息 &amp; 设置</p>
                    </div>
                </div>

                <div class="container-xl px-2 px-sm-3">
                    <div class="row">
                        <div class="col">
                            <div class="card mb-3">
                                <div class="card-header">
                                    <h6 class="mb-1">账号信息</h6>
                                    <p class="mb-0 text-muted small">更新个人信息</p>
                                </div>
                                
                                <div class="card-body">
                                    <form id="profile_form">
                                        <div class="row">
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="nickname">昵称</label>
                                                    <input type="text" class="form-control form-control-md" id="nickname" name="nickname" placeholder="请输入您的昵称" value="">
                                                </div>
                                            </div>

                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="truename">姓名</label>
                                                    <input type="text" class="form-control form-control-md" id="truename" name="truename" placeholder="请输入您的姓名" value="">
                                                </div>
                                            </div>
                                         
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="mobile">手机号码</label>
                                                    <input type="text" class="form-control form-control-md" id="mobile" name="mobile" placeholder="请输入您的手机号码" value="" disabled>
                                                </div>
                                            </div>
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="birthday">生日</label>
                                                    <input type="text" class="form-control form-control-md" id="birthday" name="birthday" placeholder="请输入您的生日" value="">
                                                </div>
                                            </div>
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="email">Email</label>
                                                    <input type="email" class="form-control form-control-md" id="email" name="email" placeholder="请输入您的邮箱地址" value="">
                                                </div>
                                            </div>
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="company">公司名称</label>
                                                    <input type="text" class="form-control form-control-md" id="company" name="company" placeholder="请输入您的公司名称" value="">
                                                </div>
                                            </div>
                                            <div class="col-12">
                                                <div class="form-group">
                                                    <label for="signature">个性签名</label>
                                                    <input type="text" class="form-control form-control-md" id="signature" name="signature" placeholder="个性签名" value="">
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <div class="card-footer d-flex justify-content-end">
                                    <!-- <button type="button" class="btn btn-link text-muted mx-1">Reset</button> -->
                                    <button type="button" class="btn btn-primary profile_btn">保 存</button>
                                </div>
                            </div>

                            <div class="card mb-3">
                                <div class="card-header">
                                    <h6 class="mb-1">密码</h6>
                                    <p class="mb-0 text-muted small">重置密码</p>
                                </div>
                                
                                <div class="card-body">
                                    <form id="pwd_form">
                                        <div class="row">
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="current-password">当前密码</label>
                                                    <input type="password" class="form-control form-control-md" id="current-password" placeholder="Current password" name="old_pwd" autocomplete="on">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="new-password">新密码</label>
                                                    <input type="password" class="form-control form-control-md" id="new-password" placeholder="New password" autocomplete="off" name="new_pwd">
                                                </div>
                                            </div>
                                            <div class="col-md-6 col-12">
                                                <div class="form-group">
                                                    <label for="repeat-password">确认密码</label>
                                                    <input type="password" class="form-control form-control-md" id="repeat-password" placeholder="Repeat password" autocomplete="off" name="confirm_pwd">
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <div class="card-footer d-flex justify-content-end">
                                    <!-- <button type="button" class="btn btn-link text-muted mx-1">Reset</button> -->
                                    <button type="button" class="btn btn-primary pwd_btn">保 存</button>
                                </div>
                            </div>

                       
                        </div>
                    </div>
                </div>
            </div>
            <!-- Profile Settings End -->

        </main>
        <!-- Main End -->

        <!-- All Modals Start -->

        <!-- Modal 1 :: Start a Conversation-->
        <div class="modal modal-lg-fullscreen fade" id="startConversation" tabindex="-1" role="dialog" aria-labelledby="startConversationLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="startConversationLabel">新建对话</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body p-0 hide-scrollbar">
                    <div class="row">
                   

                        <div class="col-12">
                                <!-- List Group Start -->
                                <ul class="list-group list-group-flush">

                                <?php foreach ($assistants as $k => $vo): ?>
                                <!-- List Group Item Start -->
                                <li class="list-group-item" data-dismiss="modal" onclick="createSession('{:$vo["id"]}')">
                                    <div class="media">
                                        <div class="avatar avatar-online mr-2">
                                            <img src="__UPLOAD__/{:$vo['image']}" alt="">
                                        </div>

                                        <div class="media-body">
                                            <h6 class="text-truncate">
                                                <a href="javascript:void(0);" class="text-reset">{:$vo['name']}</a>
                                            </h6>

                                            <p class="text-muted mb-0">Online</p>
                                        </div>
                                    </div>
                                </li>
                                <!-- List Group Item End -->
                                <?php endforeach ?>


                            </ul>
                            <!-- List Group End -->
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </div>

        <!-- Modal 2 :: Create Group -->
        <div class="modal modal-lg-fullscreen fade" id="createGroup" tabindex="-1" role="dialog" aria-labelledby="createGroupLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title js-title-step" id="createGroupLabel">&nbsp;</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body py-0 hide-scrollbar">
                        <div class="row pt-2" data-step="1" data-title="合同审查">
                            
                            <!-- <div class="col-12">
                                <div class="form-group">
                                    <label for="htsc_file_url">文件完整URL</label>
                                    <input type="text" class="form-control form-control-md" id="htsc_file_url" placeholder="支持PDF/doc/docx格式，文件大小不超过10M">
                                </div>
                            </div> -->
                            <div class="col-12">
                                <div class="form-group">
                                    <label>文件数据文件</label>
                                    <div class="custom-file">
                                        <input type="file" class="custom-file-input" name="htsc_file" id="htsc_file" />
                                        <label class="custom-file-label" for="htsc_file">选择文件，支持PDF/doc/docx格式，文件大小不超过10M</label>
                                    </div>
                                </div>
                            </div>

                            <div class="col-12">
                                <div class="row">
                                    <div class="col-12">
                                        <div class="form-group mb-0">
                                        <label>合同类型</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <div class="form-group rounded p-2 border">
                                        <div class="custom-control custom-radio">
                                            <input class="form-check-input" type="radio" name="htsc_type" id="htsc_type1" value="Sales_PartyA" checked>
                                            <label class="form-check-label" for="htsc_type1">
                                                买卖合同审查-甲方立场
                                            </label>
                                        </div>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <div class="form-group rounded p-2 border">
                                        <div class="custom-control custom-radio">
                                            <input class="form-check-input" type="radio" name="htsc_type" id="htsc_type2" value="Sales_PartyB">
                                            <label class="form-check-label" for="htsc_type2">
                                                买卖合同审查-乙方立场
                                            </label>
                                        </div>
                                        </div>
                                    </div>
                                    </div>
                            </div>
                        
                        </div>


                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-link text-muted js-btn-step mr-auto" data-orientation="cancel" data-dismiss="modal"></button> -->
                        <button type="button" class="btn btn-secondary  js-btn-step" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" onclick="sendHtsc()">发送</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal 2 :: Create Group -->
        <div class="modal modal-lg-fullscreen fade" id="aiDraw" tabindex="-1" role="dialog" aria-labelledby="createGroupLabel2" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title js-title-step" id="createGroupLabel2">&nbsp;AI作画</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body py-0">
                        <div class="row pt-2" data-title="AI作画">
                            
                            <div class="col-12">
                                <div class="form-group">
                                    <label for="aidraw_prompt">生图的文本描述</label>
                                    <textarea class="form-control form-control-md" id="aidraw_prompt" rows="3" placeholder="仅支持中文、日常标点符号。不支持英文，特殊符号，限制 200 字"></textarea>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <label for="aidraw_chicun">尺寸</label>
                                    <select class="form-control form-control-md" id="aidraw_chicun">
                                        <option value="512x512">512x512</option>
                                        <option value="640x360">640x360</option>
                                        <option value="360x640">360x640</option>
                                        <option value="1024x1024">1024x1024</option>
                                        <option value="1280x720">1280x720</option>
                                        <option value="720x1280">720x1280</option>
                                        <option value="2048x2048">2048x2048</option>
                                        <option value="2560x1440">2560x1440</option>
                                        <option value="1440x2560">1440x2560</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <label><a href="#" onclick="aidrawGj(this)">高级功能 ∨</a></label>
                                </div>
                            </div>
                            <div class="col-12" id="aidrawDiv" style="display:none;">
                                <div class="form-group">
                                    <label for="aidraw_num">生成图片数量</label>
                                    <input type="text" class="form-control form-control-md" id="aidraw_num" placeholder="默认一张，支持生成 1-8 张" value="1">
                                </div>

                                <!-- <div class="form-group">
                                    <label>参考图</label>
                                    <div class="custom-file">
                                        <input type="file" class="custom-file-input" name="aidraw_file" id="aidraw_file" />
                                        <label class="custom-file-label" for="htsc_file">大小不超过 10M，支持jpg/jpeg/png/bmp 格式</label>
                                    </div>
                                </div> -->
                            </div>

                        </div>

                        
                    </div>
                    <div class="modal-footer">
                        <!-- <button type="button" class="btn btn-link text-muted js-btn-step mr-auto" data-orientation="cancel" data-dismiss="modal"></button> -->
                        <button type="button" class="btn btn-secondary  js-btn-step" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" onclick="sendAiDraw()">发送</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal 3 :: Invite Others -->
        <div class="modal modal-lg-fullscreen fade" id="promptModal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="inviteOthersLabel">指令内容优化结果</h5>
                        
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body hide-scrollbar">
                        <form>
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <label>优化前内容：</label>
                                        <div id="prompt_content" style="font-size: 14px;color: #9a9494;"></div>
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="form-group">
                                        <label for="prompt_optimize">优化后内容：</label>
                                        <textarea class="form-control form-control-md no-resize hide-scrollbar" id="prompt_optimize" placeholder="" rows="5"></textarea>
                                    </div>
                                </div>
                            </div>
                        </form>
                        
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-link text-muted" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary prompt_paste" data-dismiss="modal">粘贴到聊天框</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal 3 :: Invite Others -->
        <div class="modal modal-lg-fullscreen fade" id="inviteOthers" tabindex="-1" role="dialog" aria-labelledby="inviteOthersLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="inviteOthersLabel">Invite Others</h5>
                        
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body hide-scrollbar">
                        <form>
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <label for="inviteEmailAddress">Email address</label>
                                        <input type="email" class="form-control form-control-md" id="inviteEmailAddress" placeholder="Type email address here" value="">
                                    </div>
                                </div>
                                <div class="col-12">
                                    <div class="form-group">
                                        <label for="inviteMessage">Invitation message</label>
                                        <textarea class="form-control form-control-md no-resize hide-scrollbar" id="inviteMessage" placeholder="Write your message here" rows="3"></textarea>
                                    </div>
                                </div>
                            </div>
                        </form>
                        
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-link text-muted" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Send Invitation</button>
                        </div>
                </div>
            </div>
        </div>
                
        <!-- Modal 4 :: Notifications -->
        <div class="modal modal-lg-fullscreen fade" id="notificationModal" tabindex="-1" role="dialog" aria-labelledby="notificationModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="notificationModalLabel">Notifications</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body p-0 hide-scrollbar">
                        <div class="row">

                            <div class="col-12">
                                    <!-- List Group Start -->
                                    <ul class="list-group list-group-flush  py-2">

                                    <!-- List Group Item Start -->
                                    <li class="list-group-item">
                                        <div class="media">
                                            <div class="btn btn-primary btn-icon rounded-circle text-light mr-2">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z"/>
                                                </svg>
                                                    
                                                <!-- Alternate :: External File link -->
                                                <!-- <img class="injectable hw-24" src="__STATIC__/index/media/heroicons/outline/user-add.svg" alt=""> -->
                                            </div>

                                            <div class="media-body">
                                                <h6>
                                                    <a href="#">Catherine richardson</a> send you a friend request
                                                </h6>

                                                <p class="text-muted mb-0">5 mins ago</p>
                                            </div>
                                        </div>
                                        <div class="d-flex justify-content-center mt-2">
                                            <button type="button" class="btn btn-outline-danger mx-1">Reject</button>
                                            <button type="button" class="btn btn-primary mx-1">Accept</button>
                                        </div>

                                    </li>
                                    <!-- List Group Item End -->

                                    <!-- List Group Item Start -->
                                    <li class="list-group-item">
                                        <div class="media">
                                            <div class="btn btn-primary btn-icon rounded-circle text-light mr-2">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                                </svg>
                                                    
                                                <!-- Alternate :: External File link -->
                                                <!-- <img class="injectable hw-24" src="__STATIC__/index/media/heroicons/outline/check-circle.svg" alt=""> -->
                                            </div>

                                            <div class="media-body">
                                                <h6>
                                                    <a href="#">Katelyn Valdez</a> accepted your friend request
                                                </h6>

                                                <p class="text-muted mb-0">25 mins ago</p>
                                            </div>
                                        </div>
                                    </li>
                                    <!-- List Group Item End -->

                                    <!-- List Group Item Start -->
                                    <li class="list-group-item">
                                        <div class="media">
                                            <div class="btn btn-primary btn-icon rounded-circle text-light mr-2">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                                </svg>

                                                <!-- Alternate :: External File link -->
                                                <!-- <img class="injectable hw-24" src="__STATIC__/index/media/heroicons/outline/photograph.svg" alt=""> -->
                                            </div>

                                            <div class="media-body">
                                                <h6>
                                                    <a href="#">Eva Walker</a> updated profile picture
                                                </h6>

                                                <p class="text-muted mb-0">5 mins ago</p>
                                            </div>
                                        </div>
                                    </li>
                                    <!-- List Group Item End -->

                                    <!-- List Group Item Start -->
                                    <li class="list-group-item">
                                        <div class="media">
                                            <div class="btn btn-primary btn-icon rounded-circle text-light mr-2">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                                </svg>
                                                    
                                                <!-- Alternate :: External File link -->
                                                <!-- <img class="injectable hw-24" src="__STATIC__/index/media/heroicons/outline/check-circle.svg" alt=""> -->
                                            </div>

                                            <div class="media-body">
                                                <h6>
                                                    <a href="#">Bonnie Torres</a> accepted your friend request
                                                </h6>

                                                <p class="text-muted mb-0">5 mins ago</p>
                                            </div>
                                        </div>
                                    </li>
                                    <!-- List Group Item End -->

                                    <!-- List Group Item Start -->
                                    <li class="list-group-item">
                                        <div class="media">
                                            <div class="btn btn-primary btn-icon rounded-circle text-light mr-2">
                                                <!-- Default :: Inline SVG -->
                                                <svg class="hw-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                                </svg>

                                                <!-- Alternate :: External File link -->
                                                <!-- <img class="injectable hw-24" src="__STATIC__/index/media/heroicons/outline/photograph.svg" alt=""> -->
                                            </div>

                                            <div class="media-body">
                                                <h6>
                                                    <a href="#">Christopher Garcia</a> updated profile picture
                                                </h6>

                                                <p class="text-muted mb-0">5 mins ago</p>
                                            </div>
                                        </div>
                                    </li>
                                    <!-- List Group Item End -->


                                </ul>
                                <!-- List Group End -->
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer justify-content-center">
                        <button type="button" class="btn btn-link text-muted">Clear all</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- All Modals End -->
    </div>
    <!-- Main Layout End -->
  

    <!-- Javascript Files -->
    <script src="__STATIC__/index/vendors/jquery/jquery-3.5.0.min.js"></script>
    <script src="__STATIC__/index/vendors/bootstrap/bootstrap.bundle.min.js"></script>
    <script src="__STATIC__/index/vendors/magnific-popup/jquery.magnific-popup.min.js"></script>
    <script src="__STATIC__/index/vendors/svg-inject/svg-inject.min.js"></script>
    <script src="__STATIC__/index/vendors/modal-stepes/modal-steps.min.js"></script>
    <script src="__STATIC__/index/js/app.min.js"></script>
    <script type="text/javascript" src="__STATIC__/admin/js/lyear-loading.js"></script><!-- loading -->

    <script type="text/javascript" src="__STATIC__/common/clipboard.min.js"></script>
    <script src="__STATIC__/common/cch.js"></script>
    <script type="text/javascript" src="__STATIC__/common/cch-util.js"></script>

    <script type="text/javascript">
        function aidrawGj(btn){
            if ($("#aidrawDiv").is(':hidden')) {
                $("#aidrawDiv").show();
                $(btn).html('高级功能 ∧');
            }else{
                $("#aidrawDiv").hide();
                $(btn).html('高级功能 ∨');
            }
        }

        function sendAiDraw(){
            var params = new FormData();

            // var files = $("#htsc_file")[0].files;
            // params.append('file',files[0]);
            params.append('prompt',$("#aidraw_prompt").val());
            params.append('chicun',$("#aidraw_chicun").val());
            params.append('num',$("#aidraw_num").val());
            params.append('session_sn',global_assistant.session_sn);

            var l = $('body').lyearloading({
                opacity: 0.5,
                spinnerSize: 'lg',
                spinnerText: '请求发送中，请稍后',
                textColorClass: 'text-info',
                spinnerColorClass: 'text-info'
            });
            
            $.ajax({
                url:'{:url("msg/aiDraw")}',
                data:params,
                type:'post',
                contentType:false,
                processData:false,
                success:function(response){
                  var data = response.data;
                  if (response.code == '2000' || response.code == '2001') {
                    var str = createAidrawMessageHtml(data.message,data.ctime);
                    str += createMsgHtml(data.reply,1,data.rtime);

                    $("#chatContent").append(str);
                    $("#aiDraw").modal('hide');

                    if (response.code == '2000') {
                        global_wait_msgs.push(response.msg_id);
                    }
                    scrollBottom();
                  }else{
                    cchUtil.message(response.msg,'danger');
                  }
                  
                  l.hide();
                }
            });
        }

        // 生成对话HTML
        function createAidrawMessageHtml(message,ctime){
            if (ctime == null || ctime == '') {
                ctime = getFamtterHours();
            }
            var msg_class = 'message self';
            var avatar = '__UPLOAD__/{:$login_user['headimgurl']}';

            var str = '<div class="'+msg_class+'">'+
                        '<div class="message-wrapper">'+
                            '<div class="message-content">'+
                                '<h6>AI作画</h6>'+
                                '<h6>生图的文本描述：'+message.prompt+'</h6>'+
                                '<h6>尺寸：'+message.chicun+'</h6>'+
                                '<h6>数量：'+message.num+'</h6>'+
                                // '<a class="popup-media" href="__STATIC__/index/htsc_file.png">'+
                                //     '<img class="img-fluid rounded" src="__STATIC__/index/htsc_file.png" alt="" style="width:100px;">'+
                                // '</a>'+
                            '</div>'+
                        '</div>'+
                    '</div>';

            return str;
        }

        // 生成对话HTML
        function createAidrawReplyHtml(message,ctime){
            console.log(message)
            if (message == null || message == '') {
              return '';
            }
            if (ctime == null || ctime == '') {
                ctime = getFamtterHours();
            }
            var msg_class = 'message';
                var avatar = '__UPLOAD__/'+global_assistant.image;

            var imgstr = '';
            for(var i in message){
                imgstr += '<a class="popup-media" href="'+message[i]+'" style="float:left;padding:5px 4px;">'+
                                    '<img class="img-fluid rounded" src="'+message[i]+'" alt="" style="width:100px;">'+
                                '</a>';
            }

            var str = '<div class="'+msg_class+'">'+
                        '<div class="message-wrapper">'+
                            '<div class="message-content">'+imgstr+'</div>'+
                        '</div>'+
                        '<div class="message-options">'+
                            '<div class="avatar avatar-sm"><img alt="" src="'+avatar+'" onerror="this.src=\'__STATIC__/index/media/avatar/3.png\'"></div>'+
                            '<span class="message-date">'+ctime+'</span>'+
                        '</div>'+
                    '</div>';
                    console.log(str)

            return str;
        }
    </script>

    <script type="text/javascript">
        var global_prompt_id = null;
        function singleOptimize(){
            var message = $("#msg_text").val();
            $.ajax({
                url:'{:url("msg/singleOptimize")}',
                data:{message:message},
                type:'post',
                dataType:'json',
                success:function(response){
                  if (response.code == 2000) {
                    global_prompt_id = response.data;
                    $("#singleOptimizeBtn").hide();
                    $("#loadingOptimizeBtn").show();

                    cchUtil.message('生成中，请稍后');
                    getPrompt();
                  }else{
                    cchUtil.message(response.msg,'danger');
                  }
                }
            });
        }

        function getPrompt(){
            if (global_prompt_id == null) { 
                $("#singleOptimizeBtn").show();
                $("#loadingOptimizeBtn").hide();
                return false; 
            }
            $.ajax({
                url:'{:url("msg/getPrompt")}',
                data:{task_id:global_prompt_id},
                type:'post',
                async:false,
                dataType:'json',
                success:function(response){
                  if (response.code == 2000) {
                    global_prompt_id = null;
                    $("#singleOptimizeBtn").show();
                    $("#loadingOptimizeBtn").hide();

                    var data = response.data;
                    $("#prompt_content").html(data.content);
                    $("#prompt_optimize").val(data.optimizeContent);

                    $("#promptModal").modal("show");
                    return false; 
                  }else if(response.code == 5001){
                    cchUtil.message('指令优化失败，请刷新重试','danger');

                    global_prompt_id = null;
                    $("#singleOptimizeBtn").show();
                    $("#loadingOptimizeBtn").hide();
                    return false; 
                  }
                }
            });
            setTimeout(function() {
                getPrompt();
            }, 5000);
        }

        $(".prompt_paste").on('click',function(){
            $("#msg_text").val($("#prompt_optimize").val());
        });
    </script>

    <script type="text/javascript">
        function getWaitMsgs(){
            var ids = global_wait_msgs;
            for(var i in ids){
                var msg_id = ids[i];
                $.ajax({
                    url:'{:url("msg/getRpley")}',
                    data:{id:msg_id},
                    type:'post',
                    dataType:'json',
                    success:function(response){
                      if (response.code == 2000) {
                        var data = response.data;
                        if (data.type == 'htsc') {
                            var str = createHtscReplyHtml(data.reply,data.rtime);    
                        }else if(data.type == 'aidraw'){
                            var str = createAidrawReplyHtml(data.reply,data.rtime);
                        }
                        
                        $("#chatContent").append(str);
                        global_wait_msgs.splice(i,1);

                        scrollBottom();
                      }
                    }
                });
            }
            setTimeout(function() {
                getWaitMsgs();
            }, 5000);
        }

        function sendHtsc(){
            var params = new FormData();

            var files = $("#htsc_file")[0].files;
            params.append('file',files[0]);
            params.append('type',$("input[name='htsc_type']:checked").val());
            params.append('session_sn',global_assistant.session_sn);

            var l = $('body').lyearloading({
                opacity: 0.5,
                spinnerSize: 'lg',
                spinnerText: '合同上传中，请稍后',
                textColorClass: 'text-info',
                spinnerColorClass: 'text-info'
            });
            
            $.ajax({
                url:'{:url("msg/htsc")}',
                data:params,
                type:'post',
                contentType:false,
                processData:false,
                success:function(response){
                  var data = response.data;
                  if (response.code == '2000' || response.code == '2001') {
                    var str = createHtscMessageHtml(data.message,data.ctime);
                    str += createMsgHtml(data.reply,1,data.rtime);

                    $("#chatContent").append(str);
                    $("#createGroup").modal('hide');

                    if (response.code == '2000') {
                        global_wait_msgs.push(response.msg_id);
                    }
                    scrollBottom();
                  }else{
                    cchUtil.message(response.msg,'danger');
                  }
                  
                  l.hide();
                }
            });
        }

        // 生成对话HTML
        function createHtscMessageHtml(message,ctime){
            if (ctime == null || ctime == '') {
                ctime = getFamtterHours();
            }
            var msg_class = 'message self';
            var avatar = '__UPLOAD__/{:$login_user['headimgurl']}';

            var str = '<div class="'+msg_class+'">'+
                        '<div class="message-wrapper">'+
                            '<div class="message-content">'+
                                '<h6>合同审查</h6>'+
                                '<h6>文件名称：'+message.name+'</h6>'+
                                '<h6>合同类型：'+(message.type == 'Sales_PartyA' ? '买卖合同审查-甲方立场' : '买卖合同审查-乙方立场')+'</h6>'+
                                '<a class="popup-media" href="__STATIC__/index/htsc_file.png">'+
                                    '<img class="img-fluid rounded" src="__STATIC__/index/htsc_file.png" alt="" style="width:100px;">'+
                                '</a>'+
                            '</div>'+
                        '</div>'+
                        '<div class="message-options">'+
                            '<div class="avatar avatar-sm"><img alt="" src="'+avatar+'" onerror="this.src=\'__STATIC__/index/media/avatar/3.png\'"></div>'+
                            '<span class="message-date">'+ctime+'</span>'+
                            '<div class="dropdown">'+
                                '<a class="text-muted" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'+
                                    '<svg class="hw-18" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
                                        '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>'+
                                    '</svg>'+
                                '</a>'+

                                '<div class="dropdown-menu">'+
                                    '<a class="dropdown-item d-flex align-items-center copy_btn" href="https://falvai.bj.bcebos.com/'+message.url+'" download="'+message.name+'">'+
                                        '<svg class="hw-18 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
                                            '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>'+
                                        '</svg>'+
                                        '<span>下载</span>'+
                                    '</a>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                    '</div>';

            return str;
        }

        // 生成对话HTML
        function createHtscReplyHtml(message,ctime){
            if (message == null || message == '') {
              return '';
            }
            if (ctime == null || ctime == '') {
                ctime = getFamtterHours();
            }
            var msg_class = 'message';
                var avatar = '__UPLOAD__/'+global_assistant.image;

            var str = '<div class="'+msg_class+'">'+
                        '<div class="message-wrapper">'+
                            '<div class="message-content" style="max-width: 100%;">'+
                                '<span>'+message+'</span>'+
                            '</div>'+
                        '</div>'+
                        '<div class="message-options">'+
                            '<div class="avatar avatar-sm"><img alt="" src="'+avatar+'" onerror="this.src=\'__STATIC__/index/media/avatar/3.png\'"></div>'+
                            '<span class="message-date">'+ctime+'</span>'+
                        '</div>'+
                    '</div>';

            return str;
        }

        // 生成对话HTML
        function createMsgHtml(message,type,ctime,msg_id){
            if (message == null || message == '') {
              return '';
            }
            if (ctime == null || ctime == '') {
                ctime = getFamtterHours();
            }
            if (type == 0) {
                var msg_class = 'message self';
                var avatar = '__UPLOAD__/{:$login_user['headimgurl']}';
            }else if(type == 1){
                var msg_class = 'message';
                var avatar = '__UPLOAD__/{:$data['image']}';
            }else{
                var msg_class = 'message msg_loading';
                var avatar = '__UPLOAD__/{:$data['image']}';
            }

            var str = '<div class="'+msg_class+'" id="'+msg_id+'">'+
                        '<div class="message-wrapper">'+
                            '<div class="message-content">'+
                                '<span>'+message+'</span>'+
                            '</div>'+
                        '</div>'+
                        '<div class="message-options">'+
                            '<div class="avatar avatar-sm"><img alt="" src="'+avatar+'" onerror="this.src=\'__STATIC__/index/media/avatar/3.png\'"></div>'+
                            '<span class="message-date">'+ctime+'</span>'+
                            '<div class="dropdown">'+
                                '<a class="text-muted" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'+
                                    '<svg class="hw-18" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
                                        '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>'+
                                    '</svg>'+
                                '</a>'+

                                '<div class="dropdown-menu">'+
                                    '<a class="dropdown-item d-flex align-items-center copy_btn" href="javascript:void(0)" data-clipboard-text="'+message+'">'+
                                        '<svg class="hw-18 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
                                            '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>'+
                                        '</svg>'+
                                        '<span>复制</span>'+
                                    '</a>'+
                                '</div>'+
                            '</div>'+
                        '</div>'+
                    '</div>';

            return str;
        }
    </script>

    <script type="text/javascript">
        $(function(){

            showUinfo();
            getWaitMsgs(); 
            // getPrompt();

            $(".profile_btn").on('click',function(){
                var params = $("#profile_form").serialize();
                $.ajax({
                    url:'{:url("user/update")}',
                    data:params,
                    type:'post',
                    dataType:'json',
                    success:function(data){
                      console.log(data)
                      if (data.code == '2000') {
                        cchUtil.message('更新成功');
                        showUinfo();
                      }else{
                        cchUtil.message(data.msg,'danger');
                      }
                    }
                });
            });

            $(".pwd_btn").on('click',function(){
                var params = $("#pwd_form").serialize();
                $.ajax({
                    url:'{:url("user/changePwd")}',
                    data:params,
                    type:'post',
                    dataType:'json',
                    success:function(data){
                      console.log(data)
                      if (data.code == '2000') {
                        cchUtil.message('更新成功');
                        showUinfo();
                      }else{
                        cchUtil.message(data.msg,'danger');
                      }
                    }
                });
            });

            $(".init_assistant").on('click',function(){
                $(".init_assistant").removeClass('active');
                $(this).addClass('active');
            });

            // $(".close_btn_mobile").on('click',function(){
            //     $("#chats-content").addClass('active'); 
            // });
        });



        var global_assistant = null; // 全局 - 助理信息
        var global_wait_msgs = [];
        // 创建一个新的session
        function createSession(assistant_id){
            $.ajax({
                url:'{:url("session/save")}',
                data:{assistant_id:assistant_id},
                type:'post',
                dataType:'json',
                success:function(data){
                    var str = '<li class="contacts-item friends" onclick="openChat(this)" data-sn="'+data.session_sn+'">'+
                            '<a class="contacts-link" href="javascript:void(0);">'+
                                '<div class="avatar avatar-online">'+
                                    '<img src="__UPLOAD__/'+data.assistant.image+'" alt="">'+
                                '</div>'+
                                '<div class="contacts-content">'+
                                    '<div class="contacts-info">'+
                                        '<h6 class="chat-name text-truncate">'+data.assistant.name+'</h6>'+
                                        '<div class="chat-time">'+data.msg.ctime+'</div>'+
                                    '</div>'+
                                    '<div class="contacts-texts">'+
                                        '<p class="text-truncate">'+data.msg.message+'</p>'+
                                    '</div>'+
                                '</div>'+
                            '</a>'+
                        '</li>';
                    $("#chatContactTab").prepend(str);
                    // $('.contacts-list .contacts-link').on('click',function(){$(".main").addClass("main-visible")})
                    // console.log($("#chatContactTab").find('li')[0])
                    $($("#chatContactTab").find('li')[0]).trigger('click');
                    // openChat2(data.session_sn)
                }
            });
        }

        function initeCreateSession(){
            var assistant_id = $(".init_assistant.active").attr('data-id');
            if (assistant_id <= 0) {
                cchUtil.message('请选择助理','danger');
            }
            createSession(assistant_id);
        }

        function deleteSessionMobile(){
            if (!confirm('确定删除？')) {
                return false;
            }
            $.ajax({
                url:'{:url("session/delete")}',
                data:{session_sn:global_assistant.session_sn},
                type:'post',
                dataType:'json',
                success:function(data){
                    if (data.code == 2000) {
                        cchUtil.message('删除成功');
                        $("#chatContactTab .contacts-item.active").remove();
                        $(".close_btn_mobile").trigger('click');
                    }else{
                        cchUtil.message(data.msg,'danger');
                    }
                }
            });
        }

        function deleteSession(){
            if (!confirm('确定删除？')) {
                return false;
            }
            $.ajax({
                url:'{:url("session/delete")}',
                data:{session_sn:global_assistant.session_sn},
                type:'post',
                dataType:'json',
                success:function(data){
                    if (data.code == 2000) {
                        cchUtil.message('删除成功');
                        $("#chatContactTab .contacts-item.active").remove();
                        $("#initChats").show();
                        $("#msgChats").hide();
                    }else{
                        cchUtil.message(data.msg,'danger');
                    }
                }
            });
        }

        function closeSession(){
            $("#chatContactTab .contacts-item.active").removeClass('active');
            $("#initChats").show();
            $("#msgChats").hide();
        }

        function clearSession(){
            if (!confirm('确定清空？')) {
                return false;
            }
            $.ajax({
                url:'{:url("session/clear")}',
                data:{session_sn:global_assistant.session_sn},
                type:'post',
                dataType:'json',
                success:function(data){
                    if (data.code == 2000) {
                        cchUtil.message('清除成功');
                        $("#chatContactTab .contacts-item.active").trigger('click');
                    }else{
                        cchUtil.message(data.msg,'danger');
                    }
                }
            });
        }
        
        // 打开对话
        function openChat(btn){
            var session_sn = $(btn).attr('data-sn');

            $("#chatContactTab .contacts-item").removeClass('active');
            $(btn).addClass('active');
            $("#initChats").hide();
            $(".main").addClass("main-visible");

            // $("#chats-content").removeClass('active'); // 手机端样式
            

            $.ajax({
                url:'{:url("agent_msg/index")}',
                data:{session_sn:session_sn},
                type:'post',
                dataType:'json',
                success:function(response){
                    // global_assistant = response.assistant;
                    // global_assistant.session_sn = session_sn;
                    // renewAssistant();

                    // global_wait_msgs = response.wait_msgs;

                    var list = response.list;
                    var str = '';
                    // str += createMsgHtml(global_assistant.greet,1,response.session.ctime);
                    for(var i in list){
                        str += '<div class="message-day">';
                        str += '<div class="message-divider sticky-top pb-2" data-label="'+i+'">&nbsp;</div>';
                                
                        for (var j in list[i]) {
                            var data = list[i][j];
                            if (data.type == 'text') {
                              str += createMsgHtml(data.message,0,data.ctime);  
                              str += createMsgHtml(data.reply,1,data.rtime);
                            }else if(data.type == 'htsc'){
                              str += createHtscMessageHtml(data.message,data.ctime);
                              str += createHtscReplyHtml(data.reply,data.rtime);
                            }else if(data.type == 'aidraw'){
                              str += createAidrawMessageHtml(data.message,data.ctime);
                              str += createAidrawReplyHtml(data.reply,data.rtime);
                            }
                            
                        }
                        str += '</div>';
                    }
                    $("#chatContent").html(str);
                    $("#msgChats").show();
                    scrollBottom();
                }
            });
        }

        // 生成对话HTML
        // function createMsgHtml(message,type,ctime){
        //     if (message == null || message == '') {
        //       return '';
        //     }
        //     if (ctime == null || ctime == '') {
        //         ctime = getFamtterHours();
        //     }
        //     if (type == 0) {
        //         var msg_class = 'message self';
        //         var avatar = '__UPLOAD__/{:$login_user['headimgurl']}';
        //     }else if(type == 1){
        //         var msg_class = 'message';
        //         var avatar = '__UPLOAD__/'+global_assistant.image;
        //     }else{
        //         var msg_class = 'message msg_loading';
        //         var avatar = '__UPLOAD__/'+global_assistant.image;
        //     }

        //     var str = '<div class="'+msg_class+'">'+
        //                 '<div class="message-wrapper">'+
        //                     '<div class="message-content">'+
        //                         '<span>'+message+'</span>'+
        //                     '</div>'+
        //                 '</div>'+
        //                 '<div class="message-options">'+
        //                     '<div class="avatar avatar-sm"><img alt="" src="'+avatar+'" onerror="this.src=\'__STATIC__/index/media/avatar/3.png\'"></div>'+
        //                     '<span class="message-date">'+ctime+'</span>'+
        //                     '<div class="dropdown">'+
        //                         '<a class="text-muted" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'+
        //                             '<svg class="hw-18" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
        //                                 '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>'+
        //                             '</svg>'+
        //                         '</a>'+

        //                         '<div class="dropdown-menu">'+
        //                             '<a class="dropdown-item d-flex align-items-center copy_btn" href="javascript:void(0)" data-clipboard-text="'+message+'">'+
        //                                 '<svg class="hw-18 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">'+
        //                                     '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>'+
        //                                 '</svg>'+
        //                                 '<span>复制</span>'+
        //                             '</a>'+
        //                         '</div>'+
        //                     '</div>'+
        //                 '</div>'+
        //             '</div>';

        //     return str;
        // }

        // 更新头部助理信息
        function renewAssistant(){
            $(".chat-header .media-body").find('h6').html(global_assistant.name);
            $(".chat-header .media-body").find('small').html(global_assistant.description);
            $(".chat-header .media-body").find('small').attr('title',global_assistant.description);
            $(".chat-header .injectable").attr('src','__UPLOAD__/'+global_assistant.image);
        }

        // 回车发送
        $("#msg_text").on('keydown',function(event){
            if(event.keyCode==13){
               sendMsg();
               return false;
            }
        });

        // 发送消息
        function sendMsg(){
            var message = $.trim($("#msg_text").val());
            if (message == null || message == '') {
                cchUtil.message('请输入内容','danger');
                return false;
            }
            var curdate = getFamtterDate();
            if ($("[data-label='"+curdate+"']").length == 0) {
                var str = '<div class="message-day">'+
                            '<div class="message-divider sticky-top pb-2" data-label="'+curdate+'">&nbsp;</div>'+
                        '</div>';
                $("#chatContent").append(str);
            }

            var str = createMsgHtml(message,0);
            $("[data-label='"+curdate+"']").parent().append(str);

            var str = createMsgHtml('AI思考中正在组织语言......',2);
            $("[data-label='"+curdate+"']").parent().append(str);

            $("#msg_text").val('');
            scrollBottom();

            if (global_assistant.request_type == 'HTTP') {
                $.ajax({
                    url:'{:url("msg/chatapi")}',
                    type:'post',
                    data:{session_sn:global_assistant.session_sn,message:message},
                    dataType:'json',
                    success:function(response){
                        var reply = response.data;
                        var str = createMsgHtml(reply,1);
                        $("[data-label='"+curdate+"']").parent().append(str);
                        $(".msg_loading").remove();
                        scrollBottom();
                    },
                    error: function(err) {
                        var str = createMsgHtml('AI异常，请重试',1);
                        $("[data-label='"+curdate+"']").parent().append(str);
                        $(".msg_loading").remove();
                        scrollBottom();
                    }
                });
            }else if (global_assistant.request_type == 'SSE') {
                if (global_assistant.type == 'baidu') {
                    $.ajax({
                        url:'{:url("msg/getToken")}',
                        type:'post',
                        data:{session_sn:global_assistant.session_sn,message:message},
                        dataType:'json',
                        success:function(response){
                            console.log(response);
                            if (response.code == 2000) {
                                var data = response.data;
                                var reply = '';
                                var str = createMsgHtml('...', 1 ,'',data.uuid);
                                $("[data-label='"+curdate+"']").parent().append(str);
                                $(".msg_loading").remove();

                                var params = {"messages":data.messages};
                                if (global_assistant.system != null && global_assistant.system != '') {
                                    params.system = global_assistant.system;
                                }
                                callBaiduWorkshopSSE(data.api_url, data.access_token, params, (msg) => {
                                    if (msg.type == "DATA") {
                                        reply += msg.content.result;
                                        $("#"+data.uuid).find('.message-content span').html(reply+'...');
                                        scrollBottom();
                                    } else if (msg.type == "END") {
                                        if( message.indexOf("我要找律师") >= 0 || message.indexOf("帮我写一份起诉状") >= 0 || message.indexOf("需要法律援助") >= 0 ) { 
                                            reply += '<br /><br />可添加微信详细咨询，微信号：delli1120';
                                        } 

                                        $("#"+data.uuid).find('.message-content span').html(reply);
                                        // 再将记录保存
                                        $.ajax({
                                            url:'{:url("msg/save")}',
                                            type:'post',
                                            data:{session_sn:global_assistant.session_sn,message:message,reply:reply},
                                            dataType:'json',
                                            success:function(response){
                                                console.log(response);
                                            }
                                        });
                                        console.log("响应返回结束");
                                    } else {
                                        console.log('-------SSE异常-------');
                                        console.log(msg);
                                    }
                                })
                            }
                        },
                        error: function(err) {
                            var str = createMsgHtml('AI异常，请重试',1);
                            $("[data-label='"+curdate+"']").parent().append(str);
                            $(".msg_loading").remove();
                            scrollBottom();
                        }
                    });
                }else{
                    var data = {};
                    data.uuid = 'msgid_'+Math.floor(Math.random() * 100000000);
                    var reply = '';
                    var str = createMsgHtml('...', 1 ,'',data.uuid);
                    $("[data-label='"+curdate+"']").parent().append(str);
                    $(".msg_loading").remove();

                    var params = {"message":message,"session_id":global_assistant.session_sn,"model_id":"360GPT-130B"};
                    call360WorkshopSSE('http://hawkeye.di.360.cn/bl-rag/api/ekm/llms/chat', params, (msg) => {
                        if (msg.type == "END") {
                            if( message.indexOf("我要找律师") >= 0 || message.indexOf("帮我写一份起诉状") >= 0 || message.indexOf("需要法律援助") >= 0 ) { 
                                reply += '<br /><br />可添加微信详细咨询，微信号：delli1120';
                            } 

                            $("#"+data.uuid).find('.message-content span').html(reply);
                            // 再将记录保存
                            $.ajax({
                                url:'{:url("msg/save")}',
                                type:'post',
                                data:{session_sn:global_assistant.session_sn,message:message,reply:reply},
                                dataType:'json',
                                success:function(response){
                                    console.log(response);
                                }
                            });
                            console.log("响应返回结束");
                        } else {
                            reply += msg.type;
                            $("#"+data.uuid).find('.message-content span').html(reply+'...');
                            scrollBottom();
                        }
                    })
                }
            }

            

            
            //判断浏览器是否支持WebSocket
            // var supportsWebSockets = 'WebSocket' in window || 'MozWebSocket' in window;
            // if (supportsWebSockets) {
            //   //建立WebSocket连接（ip地址换成自己主机ip）
            //   var  ws = new WebSocket("wss://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=24.6d97843ac4885eefaebb25c2cf34f744.2592000.1708156734.282335-34210876");
            //   ws.onopen = function(){
            //       //当WebSocket创建成功时，触发onopen事件
            //       console.log("websocket连接成功");
            //       //ws.send("hello"); //将消息发送到服务端
            //       ws.send(
            //       // JSON.stringify({
            //       //         symbols: "['00700.hk]",
            //       //         command:0,
            //       //         version:'1.0.0',
            //       //         token:'szfiu',
            //       //         heartBeat:'heartBeat'
            //       //     })
            //         '{"messages":[{"role":"user","content":"推荐下旅游路线"}],"stream":true}'
            //       );
            //   }
            //   ws.onmessage = function(e){
            //       //当客户端收到服务端发来的消息时，触发onmessage事件，参数e.data包含server传递过来的数据
            //       console.log("收到数据");
            //       console.log(e.data);
            //   }
            //   ws.onclose = function(e){
            //       //当客户端收到服务端发送的关闭连接请求时，触发onclose事件
            //       console.log("websocket已断开");
            //   }
            //   ws.onerror = function(e){
            //       //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
            //       console.log("websocket发生错误"+e);
            //   }
            // }else{
            //   layer.alert("您的浏览器不支持 WebSocket!");
            // }


            // $.ajax({
            //     url:'{:url("msg/chatapi")}',
            //     type:'post',
            //     data:{session_sn:global_assistant.session_sn,message:message},
            //     dataType:'json',
            //     success:function(response){
            //         var reply = response.data;
            //         var str = createMsgHtml(reply,1);
            //         $("[data-label='"+curdate+"']").parent().append(str);
            //         $(".msg_loading").remove();
            //         scrollBottom();
            //     },
            //     error: function(err) {
            //         var str = createMsgHtml('AI异常，请重试',1);
            //         $("[data-label='"+curdate+"']").parent().append(str);
            //         $(".msg_loading").remove();
            //         scrollBottom();
            //     }
            // });
        }

        // 千帆流式接口js调用demo
        function call360WorkshopSSE(url, body, onMessage) {
            body.stream = true;
            const decoder = new TextDecoder("utf-8");
            let buffer = '';
            let dataMsgBuffer = '';
            const processMessage = (reader) => {
                reader.read().then(content => {
                    if (content.value instanceof ArrayBuffer || ArrayBuffer.isView(content.value)) {
                        buffer += decoder.decode(content.value, {stream: !content.done});
                        const lines = buffer.split('\n');
                        buffer = lines.pop();
                        lines.forEach(line => {
                            if (line == "") { //读取到空行，一个数据块发送完成
                                onMessage({
                                    type: "DATA",
                                    content: JSON.parse(dataMsgBuffer)
                                });
                                dataMsgBuffer = "";
                                return;
                            }
                            let [type] = line.split(":", 1);
                            let content = line.substring(type.length + 1);
                            if (type == 'data') { //数据块没有收到空行之前放入buffer中
                                dataMsgBuffer += content.trim();
                            } else if (type == '' && content != '') { //服务端发送的注释，用于保证链接不断开
                                onMessage({
                                    type: "COMMENT",
                                    content: content.trim()
                                });
                            } else {
                                onMessage({
                                    type: type,
                                    content: content.trim()
                                })
                            }
                        })
                        if (!content.done) {
                            processMessage(reader);
                        } else {
                            onMessage({
                                type: "END"
                            })
                        }
                    }else{
                        onMessage({
                            type: "END"
                        })
                    }
                })
            }
            fetch(url, {
                headers: {
                    "Content-Type": "application/json",
                    "yy_user_id": "168",
                    "yy_user_name": "deyun"
                },
                method: "POST",
                body: JSON.stringify(body)
            })
                .then(response => response.body.getReader())
                .then(reader => processMessage(reader))
                .catch(error => onMessage({
                    type: "ERROR",
                    content: error
                }));
        } 

        // 千帆流式接口js调用demo
        function callBaiduWorkshopSSE(url, access_token, body, onMessage) {
            body.stream = true;
            const decoder = new TextDecoder("utf-8");
            let buffer = '';
            let dataMsgBuffer = '';
            const processMessage = (reader) => {
                reader.read().then(content => {
                    if (content.value instanceof ArrayBuffer || ArrayBuffer.isView(content.value)) {
                        buffer += decoder.decode(content.value, {stream: !content.done});
                        const lines = buffer.split('\n');
                        buffer = lines.pop();
                        lines.forEach(line => {
                            if (line == "") { //读取到空行，一个数据块发送完成
                                onMessage({
                                    type: "DATA",
                                    content: JSON.parse(dataMsgBuffer)
                                });
                                dataMsgBuffer = "";
                                return;
                            }
                            let [type] = line.split(":", 1);
                            let content = line.substring(type.length + 1);
                            if (type == 'data') { //数据块没有收到空行之前放入buffer中
                                dataMsgBuffer += content.trim();
                            } else if (type == '' && content != '') { //服务端发送的注释，用于保证链接不断开
                                onMessage({
                                    type: "COMMENT",
                                    content: content.trim()
                                });
                            } else {
                                onMessage({
                                    type: type,
                                    content: content.trim()
                                })
                            }
                        })
                        if (!content.done) {
                            processMessage(reader);
                        } else {
                            onMessage({
                                type: "END"
                            })
                        }
                    }else{
                        onMessage({
                            type: "END"
                        })
                    }
                })
            }
            url = url + '?access_token=' + access_token;
            fetch(url, {
                headers: {
                    "Content-Type": "application/json"
                },
                method: "POST",
                body: JSON.stringify(body)
            })
                .then(response => response.body.getReader())
                .then(reader => processMessage(reader))
                .catch(error => onMessage({
                    type: "ERROR",
                    content: error
                }));
        } 

        // 显示用户信息
        function showUinfo(){
            $.ajax({
                url:'{:url("user/read")}',
                type:'post',
                dataType:'json',
                success:function(response){
                    data = response.data;
                    console.log(data)
                    var fields = ['nickname','truename','mobile','birthday','email','company','signature'];
                    for (var i in fields) {
                        var field = fields[i];
                        var val = data[field];
                        $("#"+field).val(val);

                        
                        if (val == null || val == '') {
                            val = '&nbsp;';
                        }
                        $("#info_"+field).html(val);
                    }
                }
            });
        }

        // 对话滚动到底部
        function scrollBottom(){
            var scrollHeight = $('#chatContent').parent().prop("scrollHeight");
            $('#chatContent').parent().scrollTop(scrollHeight,200);

            var clipboard = new ClipboardJS('.copy_btn'); //先实例化
            clipboard.on('success', function(e) {
                cchUtil.message('复制成功');
                e.clearSelection();
            });
            clipboard.on('error', function(e) {
                alert('复制失败'); // 复制失败的事件
            });
        }




    </script>

</body>

</html>